package com.thinkgsp.util;

import java.io.IOException;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;


@Component("dateMapper")
public class CustomerDateTimeSerializer extends JsonSerializer<Date> {

	@Override
	public void serialize(Date date, JsonGenerator jgen, SerializerProvider sp)
			throws IOException, JsonProcessingException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
		//java.util.Date ud = new java.util.Date(date.getTime());
		String val = sdf.format(date);
		//System.out.println("CustomerDateTimeSerializer: format date to:" + val);
		jgen.writeString(val);
	}

}
